using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Starznet.SharePoint.SPDAT.ApplicationPages.Settings
{
    public class MembershipResetPassPage : LayoutsPageBase
    {
        protected InputFormTextBox TxtUsername;
        protected InputFormTextBox TxtPassword;
        protected InputFormTextBox TxtConfirmPassword;
        protected Panel pnlForm;
        protected Panel pnlConfirmSuccess;

        private string _sUsername;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _sUsername = Request.QueryString["Username"].ToString();
            this.TxtUsername.Text = _sUsername;
        }

        protected void BtnUpdateUser_Click(object sender, EventArgs e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                MembershipUser oUser = Membership.GetUser(_sUsername);
                String sNewTempPass = oUser.ResetPassword();
                oUser.ChangePassword(sNewTempPass, this.TxtPassword.Text);
            });

            this.pnlForm.Visible = false;
            this.pnlConfirmSuccess.Visible = true;
        }
    }
}
